#ifndef QSVGBOX_H
#define QSVGBOX_H

#include <QSvgWidget>
#include <QPaintEvent>
#include "realtimedb.h"
#include "tagwidget.h"

class QSvgBox : public TagWidget
{
    Q_OBJECT
    Q_PROPERTY(QString ImageFile READ getImageFile WRITE setImageFile)
    Q_PROPERTY(bool NoScale READ isNoScale WRITE setNoScale)
    Q_PROPERTY(int BoardWidth READ getBoardWidth WRITE setBoardWidth)
    Q_PROPERTY(QColor BoardColor READ getBoardColor WRITE setBoardColor)
    Q_PROPERTY(QString SvgCode READ getSvgCodeTemplate WRITE setSvgCodeTemplate)

public:
    Q_INVOKABLE QSvgBox(QWidget *parent = 0);
    ~QSvgBox();

    QString getImageFile();
    void setImageFile(const QString szName);
    QString getSvgCodeTemplate();
    void setSvgCodeTemplate(const QString svgCode);
    bool isNoScale();
    void setNoScale(bool bNoScale);
    int getBoardWidth();
    void setBoardWidth(int iWidth);

    QColor getBoardColor();
    void setBoardColor(QColor color);

protected:
    void resizeEvent(QResizeEvent *event);
    void paintEvent(QPaintEvent *event);

private:
    QString tagSelected;
    QString m_svgGuid;
    QString m_szImageFile;
    QString m_svgCodeGeneral;
    QString m_svgCodeTemplate;
    bool m_bNoScale;
    int m_iBoardWidth;
    QColor m_boardColorObj;
    // 默认变量值
    double value;
    QString tagValue;
    QString lastTagValue;
private:
    void updateTagValue();
    void updateSvgCode();
public slots:
    void onTagChanged(VarTag tagVar);
    void onSettingChanged(QVariant oldValue,QVariant newValue,QString settingName);
};

#endif // QSVGBOX_H
